package com.lee.springboot.service;

import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author lihaiqiang
 * @date 2022/1/21
 */
@Service
public class PayService {

    public PayService() {
        System.out.printf("%tT [%s]: 执行构造函数%n", System.currentTimeMillis(), PayService.class.getName());
    }

    @PostConstruct
    public void init() {
        System.out.printf("%tT [%s]: 我先干点啥事呢...？%n", System.currentTimeMillis(), PayService.class.getName());
    }

    /**
     * 优雅退出
     */
    @PreDestroy
    public void destroy() {
        try {
            Thread.sleep(2000);
            System.out.printf("%tT [%s]收到进程终止信号，稍等，我溜达一会......%n", System.currentTimeMillis(), PayService.class.getName());
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("%tT [%s]溜达结束，该干嘛干嘛去%n", System.currentTimeMillis(), PayService.class.getName());
    }
}
